--[[local function PlayerSpawnsFatigue(ply)

	ply:SetNWFloat("Stamina", 1500)
	ply:SetNWInt("Tired", false)
	
end

hook.Add("PlayerSpawn", "PlayerSpawnsFatigue", PlayerSpawnsFatigue)

function IWantToThink()
	for k,v in pairs(player.GetAll()) do
	
	local Staminaz = v:GetNWFloat("Stamina")
	local Tired = v:GetNWInt("Tired")
	local Moving = v:KeyDown( IN_FORWARD ) or v:KeyDown( IN_MOVERIGHT ) or v:KeyDown( IN_BACK ) or v:KeyDown( IN_MOVELEFT )	

	vel = v:GetVelocity( )
	vel.z = 0
	vel = vel:Length( )
	
	if v:GetMoveType( ) != 8 then
	if v:OnGround() then 
	
		if v:KeyDown(IN_SPEED) and vel > 0 and not ValidEntity( v:GetVehicle( ) ) and Moving and !Tired then
				v:SetNWFloat("Stamina", Staminaz - 3)
		else
				v:SetNWFloat("Stamina", Staminaz + 0.85)
		end
	end
end
		
		if Staminaz < 0 then
			v:SetNWFloat("Stamina", 0)
		elseif Staminaz > 1500 then
			v:SetNWFloat("Stamina", 1500)
		end
		
		if Staminaz <= 375 and Tired != true and !v:KeyDown(IN_SPEED) then
			v:SetNWInt("Tired", true)
		elseif Staminaz > 375 and Tired != false and !v:KeyDown(IN_SPEED) then
			v:SetNWInt("Tired", false)
		end
		
		if Staminaz == 0 then
			v:ConCommand("-speed")
		end
		
	if Tired then
			GAMEMODE:SetPlayerSpeed(v, 250, 250)		
			v:SetJumpPower( 0 )
		else
			GAMEMODE:SetPlayerSpeed(v, 250, 500)
			v:SetJumpPower( 160 )
		end
	end
end

local function SpeedBoostSprint(ply, key)
	if key == IN_SPEED and ply:GetNWInt("Tired") then
		ply.StoppingSprint = true
		return false
	end
		
	if key == IN_JUMP and !ply:GetNWInt("Tired") then
		ply:SetNWFloat("Stamina", ply:GetNWFloat("Stamina") - 250)
	end
end

hook.Add("KeyPress", "SpeedBoostSprint", SpeedBoostSprint)

local function StopBoostSprint(ply, key)
	if key == IN_SPEED and ply.StoppingSprint then
		ply.StoppingSprint = false
	end
end

hook.Add("KeyRelease", "StopBoostSprint", StopBoostSprint)

hook.Add("Think", "IWantToThink", IWantToThink)--]]

--[[function AddingFatigueVars(ply)
	ply.Stamina = 100
	ply.StopStamina = false
	umsg.Start("StaminaReset", ply)
	umsg.End()
end

hook.Add("PlayerSpawn", "AddingFatigueVars", AddingFatigueVars)

timer.Create("CreateStaminaProcess",0.1,0,function()
	for k,v in pairs(player.GetAll()) do
		if v:GetMoveType( ) == 8 then return end
		if v:GetVelocity():Length() > 1 then
			if v:KeyDown(IN_SPEED) then
				v.Stamina = math.Clamp(v.Stamina - DECREASE_RATE,0,100)
			else
				v.Stamina = math.Clamp(v.Stamina + INCREASE_RATE,0,100) 
			end
		else 
			v.Stamina = math.Clamp(v.Stamina + INCREASE_RATE,0,100) 
		end
		
		if v:KeyDown(IN_JUMP) and v.Stamina > 30 then
		v.Stamina = v.Stamina - 20
		end
		
		
		if v.Stamina <= 0 then
			v:SetRunSpeed(WALK_SPEED)
			v.StopStamina = true
		elseif v.StopStamina and v.Stamina > 30 then
			v:SetRunSpeed(RUN_SPEED)
			v.StopStamina = false
			end
		end
	end
end)

local function SpeedBoostSprint(ply, key)
	if key == IN_JUMP and ply.Stamina > 30 then
		return false
	end
end

hook.Add("KeyPress", "SpeedBoostSprint", SpeedBoostSprint)--]]